package lib

import (
	"algorithms/ds"
)

func init() {
	Probs = append(Probs, Problem{
		Num:         203,
		Discription: "移除链表中的指定元素",
		Level:       1,
		Labels: map[string]int{
			"虚拟头节点": 1,
			"双指针滑动": 1,
		},
	})
}

func RemoveElements(head *ds.ListNode, val int) *ds.ListNode {
	preHead := &ds.ListNode{
		Next: head,
	}
	pre := preHead
	for pre.Next != nil {
		cur := pre.Next
		next := cur.Next
		if cur.Val == val {
			pre.Next = next
		} else {
			pre = pre.Next
		}
	}

	return preHead.Next
}
